package com.jds.test.bio.p3;

/**
 * https://www.cnblogs.com/silyvin/articles/11985950.html
 * Created by joyce on 2019/11/26.
 */
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

    public static final int PORT = 12123;
    public static final int BUFFER_SIZE = 1024;

    public static void main(String [] f) throws IOException, InterruptedException {

        boolean flush = false;
        if(f != null && f.length > 0)
            flush = true;

        System.out.println("flush - " + flush);
        new Server().server(flush);
    }

    //服务端代码
    public void server(boolean flush) throws IOException, InterruptedException{
        ServerSocket ss = new ServerSocket(PORT);
        while(true) {
            Socket s = ss.accept();

            //这里向网络进行两次写入
            s.getOutputStream().write("hello ".getBytes());
            if(flush)
                s.getOutputStream().flush();
            s.getOutputStream().write("guanxinquan ".getBytes());
            s.getOutputStream().flush();
            s.close();
        }
    }
}